#include "pch.h"
#include <iostream>
#include<string>
#include <conio.h>
#include "front.h"
#include"binarySerialize.h"
using namespace std;
string path;
string menuChoose;
string mainChoose;
void opFinish(bool i = true)
{
	if (i)
		_getch();
	mainChoose == "0";
	menuChoose == "0";
}
bool print()
{
	cout << "一 包裹管理。" << endl;
	cout << "二 物流查询。" << endl;
	cout << "三 快递邮寄。" << endl;
	cout << "四 硬盘存取。" << endl;
	cout << "请输入您要进行的操作。（一，二，三或四）" << endl;
	cin >> mainChoose;
	if (mainChoose == "一")
	{
		cout << "0.退回" << endl;
		cout << "1.包裹入库" << endl;
		cout << "2.包裹查询" << endl;
		cout << "3.包裹出库" << endl;
		cout << "4.库存盘点" << endl;
		cout << "请输入您要进行的操作。（0，1，2，3或4）" << endl;
		cin >> menuChoose;
		if (menuChoose == "1")
		{
			package e=front::packageInStorage();
			cout << "取件码为：" << endl;
			cout<<e.getPickupCode();
			opFinish();
			return true;
		}
		if (menuChoose == "2")
		{
			string z;
			cout << "请输入取件码。" << endl;
			cin >> z;
			cout << dataOperation::queryPackage(z) << endl;
			opFinish();
			return true;
		}
		if (menuChoose == "3")
		{

			string z;
			cout << "请输入取件码。" << endl;
			cin >> z;
			dataOperation::queryPackage(z)->outStock(*dataOperation::systemTime);
			opFinish();
			return true;
		}
		if (menuChoose == "4")
		{
			int a, b;
			tie(a, b) = dataOperation::packageStockTaking();
			cout << "在库包裹数" << endl;
			cout << b << endl;
			cout << "出库包裹数" << endl;
			cout << a << endl;
			opFinish();
			return true;
		} 
		opFinish();
		return true;
	}
	if (mainChoose == "三")
	{
		cout << "0.退回" << endl;
		cout << "1.寄快递" << endl;
		cout << "2.结款" << endl;
		cout << "3.未付款查询" << endl;
		cout << "请输入您要进行的操作。（0,1，2或3）" << endl;
		cin >> menuChoose;
		if (menuChoose == "1")
		{
			cout << front::ExpressMail().getCourierNumber() << endl;
			cout << "快递单号为：" << endl;
			opFinish();
			return true;
		}
		if (menuChoose == "2")
		{
			opFinish();
			return true;
		}
		if (menuChoose == "3")
		{
			cout << "未付款的为：" << endl;
			list<express*> le = dataOperation::getAllUnpaidExpress();
			for (express* e : le)
				cout << e->getExpressBill() << endl;;
			opFinish();
			return true;
		}
	}
	if (mainChoose == "二")
	{
		cout << "0.退回" << endl;
		cout << "1.查询" << endl;
		if (menuChoose == "1")
		{
			string zx;
			cout << "请输入您要查询的快递的单号：" << endl;
			cin >> zx;
			cout << dataOperation::queryExpress(zx)->getLogisticsInformation() << endl;
		}
		opFinish();
		return true;
	}
	if (mainChoose == "四")
	{
		cout << "0.退回" << endl;
		cout << "1.包裹保存" << endl;
		cout << "2.包裹读取" << endl;
		cout << "3.快递保存" << endl;
		cout << "4.快递读取" << endl;
		cout<<"请输入您要进行的操作。（0,1,2,3或4）" << endl;
		cin >> menuChoose;
		if (menuChoose == "1")
		{
			binarySerialize::saveSTLObject<list<package>, package>(path, dataOperation::allPackage);
			cout << "存储成功" << endl;
			opFinish();
			return true;
		}
		if (menuChoose == "2")
		{
			binarySerialize::loadSTLObject<list<package>, package>(path, dataOperation::allPackage);
			cout << "读取成功" << endl;
			opFinish();
			return true;
		}
		if (menuChoose == "3")
		{
			binarySerialize::saveSTLObject<list<express>, express>(path+"e", dataOperation::allExpress);
			cout << "存储成功" << endl;
			opFinish();
			return true;
		}
		if (menuChoose == "4")
		{
			binarySerialize::loadSTLObject<list<package>, package>(path+"e", dataOperation::allPackage);
			cout << "读取成功" << endl;
			opFinish();
			return true;
		}
		opFinish();
		return true;
	}
	return false;
}

date* date::knowday;
date* dataOperation::systemTime;
list<package> dataOperation::allPackage;
list<express> dataOperation::allExpress;

void cls()
{
	system("cls");
}

int main()
{
	path = "D:/快递驿站/123";
	dataOperation::init();
	dataOperation::systemTime = new date(2019, 12, 17, 12, 12);
	cout << "快递驿站！！！——哈哈哈啊哈哈哈" << endl;
	opFinish(false);
	while (1)
	{
		if (print() == false)
		{
			if (mainChoose == "0")
				mainChoose = _getch();
			else if (menuChoose == "0")
				menuChoose = _getch();

			if (menuChoose == "0")
				opFinish(false);
		}
		cls();
	}
}
